//
// Copyright (C) 2008 Jackson Harper (jackson@ximian.com)

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//

using System;
using System.Web;
using System.Text;

using Gaia.WebWidgets;


namespace Grr
{
    public class MultiAccordion : Accordion
    {
        public MultiAccordion()
        {
        }

        public bool IsExpanded
        {
            get
            {
                if (ViewState["IsExpanded"] == null)
                    return false;
                return (bool)ViewState["IsExpanded"];
            }
            set
            {
                ViewState["IsExpanded"] = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (Visible)
            {
                Manager.Instance.AddInclusionOfFile("scripts/MultiAccordion.js", typeof(MultiAccordion), "MultiAccordion", "MultiAccordion.browserFinishedLoading");
            }
        }

        protected override string GetObjectScript()
        {
            // Retrieving aspects registration
            StringBuilder builder = new StringBuilder();

            // Rendering Aspects
            Manager.RenderAspects(builder, Aspects);

            string code = string.Format("Gaia.Control.registerControl(new Gaia.MultiAccordion('{0}_DIV', " +
                "{{is_expanded:{1}, height:{2}, heightOfBorders:{3}, className:'{4}'{5}}}))",
                ClientID,
                (IsExpanded ? "true" : "false"),
                Height.Value.ToString("0"),
                HeightOfBorders,
                CssClass,
                (builder.Length > 0 ? "," + builder.ToString() : ""));
            code += ";";
            return code;
        }
    }
}
